package com.zx.article.articleType.service.impl;

import java.util.List;

import com.zx.article.articleType.dao.IArticleTypeDao;
import com.zx.article.articleType.dao.impl.ArticleTypeDaoImpl;
import com.zx.article.articleType.model.ArticleTypeModel;
import com.zx.article.articleType.service.IArticleTypeService;
import com.zx.article.typePay.service.impl.TypePayServiceImpl;

public class ArticleTypeServiceImpl implements IArticleTypeService {

	private IArticleTypeDao articleTypeDao = new ArticleTypeDaoImpl();

	@Override
	public String add(String name) {
		if (articleTypeDao.getModel(name) != null) {
			return "repeat";
		}
		new TypePayServiceImpl().addId(name);
		return "1".equals(articleTypeDao.insert(name)) ? "success" : "fail";
	}

	@Override
	public List<ArticleTypeModel> getAll(ArticleTypeModel articleTypeModel) {
		return articleTypeDao.queryList(articleTypeModel);
	}

	@Override
	public int getCount(ArticleTypeModel articleTypeModel) {
		String name = articleTypeModel.getName();
		articleTypeModel.setName("%" + name + "%");
		return articleTypeDao.queryCount(articleTypeModel);
	}

	@Override
	public String del(String name) {
		int count = articleTypeDao.queryArticleCount(name);
		if (count != 0) {
			return "has";
		}
		return "1".equals(articleTypeDao.delete(name)) ? "success" : "fail";
	}

	@Override
	public String upd(ArticleTypeModel articleTypeModel) {
		if (articleTypeDao.getModel(articleTypeModel.getName()) != null) {
			return "repeat";
		}
		return "1".equals(articleTypeDao.updata(articleTypeModel)) ? "success" : "fail";
	}

}
